function add0(num) {
	return Number(num) > 9 ? Number(num) + '' : '0' + Number(num)
}

export function colourBlend(c1, c2, ratio) {
	ratio = Math.max(Math.min(Number(ratio), 1), 0)
	let r1 = parseInt(c1.substring(1, 3), 16)
	let g1 = parseInt(c1.substring(3, 5), 16)
	let b1 = parseInt(c1.substring(5, 7), 16)
	let r2 = parseInt(c2.substring(1, 3), 16)
	let g2 = parseInt(c2.substring(3, 5), 16)
	let b2 = parseInt(c2.substring(5, 7), 16)
	let r = Math.round(r1 * (1 - ratio) + r2 * ratio)
	let g = Math.round(g1 * (1 - ratio) + g2 * ratio)
	let b = Math.round(b1 * (1 - ratio) + b2 * ratio)
	r = ('0' + (r || 0).toString(16)).slice(-2)
	g = ('0' + (g || 0).toString(16)).slice(-2)
	b = ('0' + (b || 0).toString(16)).slice(-2)
	return '#' + r + g + b
}

export function setAge(time) {
	let timeYear = new Date(time).getFullYear();
	let nowYear = new Date().getFullYear()
	return nowYear - timeYear
}

export function getPickerOptions() {
	return {
		shortcuts: [{
			text: '最近一周',
			onClick(picker) {
				const end = new Date();
				const start = new Date();
				start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
				picker.$emit('pick', [start, end]);
			}
		}, {
			text: '最近一个月',
			onClick(picker) {
				const end = new Date();
				const start = new Date();
				start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
				picker.$emit('pick', [start, end]);
			}
		}, {
			text: '最近三个月',
			onClick(picker) {
				const end = new Date();
				const start = new Date();
				start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
				picker.$emit('pick', [start, end]);
			}
		}]
	}
}
export function setDate({
	time = new Date().getTime(),
	type = "YYYY-MM-DD hh:mm:ss"
}) {
	let date = new Date(time);
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
	let h = date.getHours();
	let m = date.getMinutes();
	let s = date.getSeconds();

	return type.replace('YYYY', year).replace('MM', add0(month)).replace('DD', add0(day)).replace('hh', add0(h))
		.replace('mm', add0(m)).replace('ss', add0(s))
}

export function setSX(e) {
	let list = [{
		txt: '室',
		tag: ['卧室', '寝室']
	}, {
		txt: '卫',
		tag: ['卫生间', '洗手间']
	}, {
		txt: '厅',
		tag: ['餐厅', '客厅']
	}, {
		txt: '厨',
		tag: ['厨房']
	}];
	let str = e;
	for (let i in list) {
		if (list[i].tag.indexOf(e) != -1) {
			str = list[i].txt
			break;
		}
	}
	return str;
}